<template>
  <basicModal @register="modalRegister" ref="modalRef" class="basicModal" @on-ok="okModal">
    <template #default>
      <n-card :bordered="false" title="是否开放下载">
        <n-radio-group v-model:value="isDown" name="radiogroup">
          <n-space>
            <n-radio  :key="1" :value="1">
            否
            </n-radio>
            <n-radio  :key="0" :value="0">
              是
            </n-radio>
          </n-space>
        </n-radio-group>
      </n-card>
      <n-card :bordered="false" title="备注">
          <n-input type="textarea"  v-model:value="fileRemark" :resizable="false"></n-input>
      </n-card>
      <n-card :bordered="false" title="附件">
        <n-upload  :multiple="true"  v-model:file-list="fileList" ref="uploadRef" :customRequest="customRequest">
          <n-button>上传文件</n-button>
        </n-upload>
      </n-card>
    </template>
  </basicModal>
</template>

<script lang="ts" setup>
import {useModal} from '@/components/Modal';
import {UploadCustomRequestOptions} from "naive-ui";
import commonUtil from '@/utils/common-util'
import {propTypes} from "@/utils/propTypes";
const modalRef: any = ref(null);
const [modalRegister, {openModal, closeModal, setSubLoading}] = useModal({
  title: '导入文件',
});
const isDown = ref(1)
const fileRemark = ref('')
const uploadRef = ref(null)
const fileList = ref([])
const props = defineProps({
  uploadPath:propTypes.any.def({})
})
const emits = defineEmits(['submit','modalRegister'])

function showModal() {
  openModal();
}
function okModal() {
  let remark= fileRemark.value ? fileRemark.value  :'';
  let params = {
    "downloadLimit":isDown.value,
    "remark":remark,
    "zipList":toRaw(unref(fileList))
  }
  setSubLoading(false)
  emits('submit',params)
  closeModal()
}

const customRequest = (options: UploadCustomRequestOptions) => {
  let file:any = options.file
  const fileMsg = commonUtil.getFileNameAndType(file.name);

}
defineExpose({
  showModal,modalRegister
})
</script>

<style scoped>

</style>
